package org.tso.bs.server;

import java.net.ServerSocket;
import java.net.Socket;

import org.apache.log4j.Logger;
import org.tso.bs.server.handler.Handler;

public class BSServer {
	Logger log = Logger.getLogger(BSServer.class);

	public void run() throws Exception {
		log.info("BS server initing...");
		HandlerFactory hf = new HandlerFactory();
		ServerSocket ss = new ServerSocket(1161);
		log.info("startup server socket,port :1161.");
		for (;;) {
			Socket s = ss.accept();
			log.info("new accept.");
			try {
				Head head = new Head(s);
				Handler handler = hf.createHandler(head);
				Thread t = new Thread(handler);
				t.start();
			} catch (Exception e) {
				log.error(e);
			}
		}
	}

	public static void main(String[] args) throws Exception {
		BSServer instance = new BSServer();
		instance.run();

	}

}
